package com.jaws.demo.controller;

import com.jaws.demo.service.AccountServiceImpl;
import com.jaws.demo.vo.AccountTypeEnum;
import com.jaws.demo.vo.BatchOpenAccountReq;
import com.jaws.demo.vo.OpenAccountReq;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RefreshScope
@Slf4j
public class TransactionController {

	@Resource
	AccountServiceImpl accountService;

	/**
	 * mq操作
	 *
	 * @author maojian
	 * @date 2018-03-12 10:56:45
	 * @since v1.0.0
	 */
	@ApiOperation(value = "测试多数据源事务控制")
	@PostMapping(value = "/testTrs")
	public void testTrs() {
		BatchOpenAccountReq params = new BatchOpenAccountReq();
		List<OpenAccountReq> list = Lists.newArrayList();
		params.setList(list);

		OpenAccountReq req1 = new OpenAccountReq();
		OpenAccountReq req2 = new OpenAccountReq();
		list.add(req1);
		list.add(req2);

		req1.setUserId("lampard000000001");
		req1.setUserName("lampard-test-AAAAA");
		req1.setAccountType(AccountTypeEnum.PERSIONAL);
		req1.setDepositAccountNo("18612997785");
		req1.setLoginPwd("AAAAA");
		req1.setDrawPwd("AAAAA");
		req1.setRemark("测试事务");

		req2.setUserId("lampard000000002");
		req2.setUserName("lampard-test-BBBBBB");
		req2.setAccountType(AccountTypeEnum.PERSIONAL);
		req2.setDepositAccountNo("18612997786");
		req2.setLoginPwd("AAAAA");
		req2.setDrawPwd("AAAAA");
		req2.setRemark("测试事务");


		accountService.openAccount(params);
	}

}
